import unittest
import requests
import sys
import os
from parameterized import parameterized
# 加入项目根路径
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
from tools import read_json
from api import log
from tools import parser_html
from api.api_register_login import ApiRegisterLogin
from api.api_tender import ApiTender
class Test03Tender(unittest.TestCase):
    def setUp(self) -> None:
        self.session = requests.session()
        self.tender = ApiTender(self.session)
        ApiRegisterLogin((self.session)).api_login()
        
    def tearDown(self) -> None:
        self.session.close()
        

    @parameterized.expand(read_json("tender.json", "tender"))
    def test01_tender(self, amount, except_text):
        try:
            r = self.tender.api_tender(amount)
                #三方开户
            if amount == 100:
                result =  parser_html(r)
                r = self.session.post(url=result[0], data=result[1]) 
        
                print("三方投资接口结果：",r.text)
                log.info("执行结果为：{}".format(r.text))
                self.assertIn(except_text, r.text)
            else:
                self.assertIn(except_text, r.text)
        except Exception as e:
            log.error("断言错误:{}".format(e))
            raise

if __name__ == "__main__":
    # 执行测试
    unittest.main()